package com.dream.inspect.modules.business.service.impl;

import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.dream.inspect.modules.business.dao.SysXzqhDao;
import com.dream.inspect.modules.business.entity.SysXzqhEntity;
import com.dream.inspect.modules.business.service.SysXzqhService;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


@Service("sysXzqhService")
public class SysXzqhServiceImpl extends ServiceImpl<SysXzqhDao, SysXzqhEntity> implements SysXzqhService {

@Override
public List<SysXzqhEntity> findProvincesAndCities(){
    List<SysXzqhEntity>  list=  baseMapper.findAll();

    Map<Long, Object> map = new HashMap<Long, Object>();
    for (SysXzqhEntity t : list) {
        map.put(t.getXzqhId(), t);
    }
    List<SysXzqhEntity> result = new ArrayList<SysXzqhEntity>();
    for (int i = 0; i < list.size(); i++) {
        SysXzqhEntity temp2 = list.get(i);
        if (null != map.get(temp2.getParentId())) {
            (((SysXzqhEntity) map.get(temp2.getParentId())).getChildren()).add(temp2);
            continue;
        } else {
            result.add(temp2);
        }
    }
    return result;
}

    @Override
    public List<SysXzqhEntity> findXzqhByParentId(Long parentId) {
        return baseMapper.findByParentId(parentId);
    }
}
